﻿<?php

// on vérifie que cette page est appelée à partir de l'index et que l'utilisateur a le droit de consultation
	if(isset($_SESSION) && ($GLOBALS['USER']['level'] >= 2 || $GLOBALS['USER']['admin'])){
		
      // Gestion des onglets
   	if(isset($_GET['oglt'])){
   		switch($_GET['oglt']){
   		case 1: $oglt = 1; break;
   		case 2: $oglt = 2; break;
   		default: $oglt = 1; break;
   		}
   	}else{
   		$oglt = 1;
   	}
      
      
		$tabF=array();
      $query_cherche_taxon = "SELECT DISTINCT t.CODETAXON as id, a.ABREVIATIONAUTEUR AS auteur, f.NOMFAMILLE AS famille, sf.NOMSOUSFAMILLE AS sous_famille, g.NOMGENRE AS genre, sg.NOMSOUSGENRE AS sous_genre, e.CODEESPECE as idEspece, e.NOMESPECE AS espece, se.NOMSOUSESPECE AS sous_espece, v.NOMVARIETE AS variete ";
      $query_cherche_taxon .= "FROM taxon t ";
      $query_cherche_taxon .= "INNER JOIN classification c ON c.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "LEFT JOIN est_de_famille l1 INNER JOIN famille f ON f.CODEFAMILLE = l1.CODEFAMILLE ON l1.CODETAXON = t.CODETAXON AND l1.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "LEFT JOIN est_de_sous_famille l11 INNER JOIN sous_famille sf ON sf.CODESOUSFAMILLE = l11.CODESOUSFAMILLE ON l11.CODETAXON = t.CODETAXON AND l11.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "LEFT JOIN appartient_a_genre l2 INNER JOIN genre g ON g.CODEGENRE = l2.CODEGENRE ON l2.CODETAXON = t.CODETAXON AND l2.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "LEFT JOIN appartient_a_sous_genre l22 INNER JOIN sous_genre sg ON sg.CODESOUSGENRE = l22.CODESOUSGENRE ON l22.CODETAXON = t.CODETAXON AND l22.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "LEFT JOIN est_de_espece l3 INNER JOIN espece e ON e.CODEESPECE = l3.CODEESPECE ON l3.CODETAXON = t.CODETAXON AND l3.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "LEFT JOIN est_de_sous_espece l33 INNER JOIN sous_espece se ON se.CODESOUSESPECE = l33.CODESOUSESPECE ON l33.CODETAXON = t.CODETAXON AND l3.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "LEFT JOIN a_comme_variete l4 INNER JOIN variete v ON v.CODEVARIETE = l4.CODEVARIETE ON l4.CODETAXON = t.CODETAXON AND l4.CODECLASSIFICATION = t.CODECLASSIFICATION ";
      $query_cherche_taxon .= "INNER JOIN auteur a ON (e.CODEAUTEUR = a.CODEAUTEUR OR se.CODEAUTEUR = a.CODEAUTEUR OR v.CODEAUTEUR = a.CODEAUTEUR) ";
		
      
      
      $query_cherche_taxon .= "WHERE t.CODETAXON = ".$_GET['taxId']." ";
   
      $result_cherche_taxon = mysql_query($query_cherche_taxon, $connexion) or logError("affiche TAXONS-".$query_cherche_taxon."-".mysql_error());
   
		$tabF=mysql_fetch_assoc($result_cherche_taxon);
	
		mysql_free_result($result_cherche_taxon);
      
      // récupération noms vernaculaires
      $query_recuperation_nver = "SELECT NV.NOMVERNACULAIRE, air.NOMAIREGEOGRAPHIQUE FROM nom_vernaculaire NV ";
      $query_recuperation_nver .= "INNER JOIN se_nomme_couramment INNER JOIN taxon t ON t.CODETAXON = se_nomme_couramment.CODETAXON AND t.CODETAXON = ".$tabF['id']." AND NV.CODENOMVERNACULAIRE = se_nomme_couramment.CODENOMVERNACULAIRE ";
      $query_recuperation_nver .= "INNER JOIN aire_geographique air ON se_nomme_couramment.CODEAIREGEOGRAPHIQUE = air.CODEAIREGEOGRAPHIQUE ";


		$result_recuperation_nver = mysql_query($query_recuperation_nver, $connexion) or logError("RECUP NOM VERNACULAIRE-".$query_recuperation_nver."-".mysql_error());
		$nb_nver = mysql_num_rows($result_recuperation_nver);
		if($nb_nver == 0){
			$tabF['nver'] = "<i> Aucun nom vernaculaire </i><br /><br />";

		} else {
         $cpt = 0;
		   while($tab = mysql_fetch_assoc($result_recuperation_nver)){
			   $tabF['nver'][$cpt] = "<li>".$tab['NOMVERNACULAIRE']." (<i>".$tab['NOMAIREGEOGRAPHIQUE']."</i>)</li>";
            $cpt++;
		   }
         $tabF['nver'][$cpt] = "<br />";
		}
		mysql_free_result($result_recuperation_nver);
	
      // récupération aires géographiques
      $query_recuperation_air = "SELECT air.NOMAIREGEOGRAPHIQUE FROM aire_geographique air ";
      $query_recuperation_air .= "INNER JOIN espece e ON  e.NOMESPECE = ".mysqlString($tabF['espece'])." AND air.CODEAIREGEOGRAPHIQUE = e.CODEAIREGEOGRAPHIQUE ";
										
		$result_recuperation_air = mysql_query($query_recuperation_air, $connexion) or logError("GET AIRE GEOGRAPHIQUE-".$query_recuperation_air."-".mysql_error());
		$nb_air = mysql_num_rows($result_recuperation_air);
		if($nb_air == 0){
			$tabF['air'] = "<i> Aucune aire géographique </i><br /><br />";
		} else {
         $cpt = 0;
			while($tab = mysql_fetch_assoc($result_recuperation_air)){
			   $tabF['air'][$cpt] = "<li>".$tab['NOMAIREGEOGRAPHIQUE']."</li>";
            $cpt++;
		   }
         $tabF['air'][$cpt] = "<br />";
		}
		
		mysql_free_result($result_recuperation_air);
      
      // récupération proprietes especes
      $query_recuperation_prop = "SELECT PE.NOMPROPRIETEESPECE FROM propriete_espece PE ";
      $query_recuperation_prop .= "INNER JOIN possede_propriete PP  ON  PP.CODEESPECE = ".mysqlString($tabF['idEspece'])." AND PP.CODEPROPRIETEESPECE = PE.CODEPROPRIETEESPECE ";
										
		$result_recuperation_prop = mysql_query($query_recuperation_prop, $connexion) or logError("GET PROPRIETE ESPECE-".$query_recuperation_prop."-".mysql_error());
		$nb_prop = mysql_num_rows($result_recuperation_prop);
		if($nb_prop == 0){
			$tabF['prop'] = "<i> Aucune propriété d'espèce </i><br /><br />";
		} else {
         $cpt = 0;
			while($tab = mysql_fetch_assoc($result_recuperation_prop)){
			   $tabF['prop'][$cpt] = "<li>".$tab['NOMPROPRIETEESPECE']."</li>";
            $cpt++;
		   }
         $tabF['prop'][$cpt] = "<br />";
		}
		
		mysql_free_result($result_recuperation_prop);
      
      
      // récupération types biologiques
      $query_recuperation_tybi = "SELECT TB.NOMTYPEBIOLOGIQUE, air.NOMAIREGEOGRAPHIQUE FROM type_biologique TB ";
      $query_recuperation_tybi .= "INNER JOIN est_de_type_biologique INNER JOIN taxon t ON t.CODETAXON = est_de_type_biologique.CODETAXON AND t.CODETAXON = ".$tabF['id']." AND TB.CODETYPEBIOLOGIQUE = est_de_type_biologique.CODETYPEBIOLOGIQUE ";
      $query_recuperation_tybi .= "INNER JOIN aire_geographique air ON est_de_type_biologique.CODEAIREGEOGRAPHIQUE = air.CODEAIREGEOGRAPHIQUE ";

		$result_recuperation_tybi = mysql_query($query_recuperation_tybi, $connexion) or logError("GET TYPE BIOLOGIQUE-".$query_recuperation_tybi."-".mysql_error());
		$nb_tybi = mysql_num_rows($result_recuperation_tybi);
		if($nb_tybi == 0){
			$tabF['tybi'] = "<i> Aucun type biologique </i><br /><br />";
		} else {
         $cpt = 0;
			while($tab = mysql_fetch_assoc($result_recuperation_tybi)){
			   $tabF['tybi'][$cpt] = "<li>".$tab['NOMTYPEBIOLOGIQUE']." (<i>".$tab['NOMAIREGEOGRAPHIQUE']."</i>)</li>";
            $cpt++;
		   }
         $tabF['tybi'][$cpt] = "<br />";
		}
		
		mysql_free_result($result_recuperation_tybi);
      
      
      // récupération milieux biologiques
      $query_recuperation_mibi = "SELECT MB.NOMMILIEUBIOLOGIQUE, air.NOMAIREGEOGRAPHIQUE FROM milieu_biologique MB ";
      $query_recuperation_mibi .= "INNER JOIN se_trouve_en_milieu_biologique inMB INNER JOIN taxon t ON t.CODETAXON = inMB.CODETAXON AND t.CODETAXON = ".$tabF['id']." AND MB.CODEMILIEUBIOLOGIQUE = inMB.CODEMILIEUBIOLOGIQUE ";
      $query_recuperation_mibi .= "INNER JOIN aire_geographique air ON inMB.CODEAIREGEOGRAPHIQUE = air.CODEAIREGEOGRAPHIQUE ";

		$result_recuperation_mibi = mysql_query($query_recuperation_mibi, $connexion) or logError("GET MILIEU BIOLOGIQUE-".$query_recuperation_mibi."-".mysql_error());
		$nb_mibi = mysql_num_rows($result_recuperation_mibi);
		if($nb_mibi == 0){
			$tabF['mibi'] = "<i> Aucun milieu biologique </i><br /><br />";
		} else {
         $cpt = 0;
			while($tab = mysql_fetch_assoc($result_recuperation_mibi)){
			   $tabF['mibi'][$cpt] = "<li>".$tab['NOMMILIEUBIOLOGIQUE']." (<i>".$tab['NOMAIREGEOGRAPHIQUE']."</i>)</li>";
            $cpt++;
		   }
         $tabF['mibi'][$cpt] = "<br />";
		}
		
		mysql_free_result($result_recuperation_mibi);
      
      
      // récupération etats phenologiques
      $query_recuperation_ephe = "SELECT ephe.NOMETATPHENOLOGIQUE FROM etat_phenologique ephe ";
      $query_recuperation_ephe .= "INNER JOIN a_ete_vu_taxon vutax INNER JOIN taxon t ON t.CODETAXON = vutax.CODETAXON AND t.CODETAXON = ".$tabF['id']." AND ephe.CODEETATPHENOLOGIQUE = vutax.CODEETATPHENOLOGIQUE ";

		$result_recuperation_ephe = mysql_query($query_recuperation_ephe, $connexion) or logError("GET ETAT PHENOLOGIQUE-".$query_recuperation_ephe."-".mysql_error());
		$nb_ephe = mysql_num_rows($result_recuperation_ephe);
		if($nb_ephe == 0){
			$tabF['ephe'] = "<i> Aucun état phénologique </i><br /><br />";
		} else {
         $cpt = 0;
			while($tab = mysql_fetch_assoc($result_recuperation_ephe)){
			   $tabF['ephe'][$cpt] = "<li>".$tab['NOMETATPHENOLOGIQUE']."</li>";
            $cpt++;
		   }
         $tabF['ephe'][$cpt] = "<br />";
		}
		
		mysql_free_result($result_recuperation_ephe);
      
      
      // récupération sachets graines
      $query_recuperation_sgrain = "SELECT sg.QUANTITEGRAINESDISPONIBLES,sg.REFERENCESACHETGRAINES FROM sachet_graines sg ";
      $query_recuperation_sgrain .= "INNER JOIN taxon t ON t.CODETAXON = sg.CODETAXON AND t.CODETAXON = ".$tabF['id'];

		$result_recuperation_sgrain = mysql_query($query_recuperation_sgrain, $connexion) or logError("GET sachet graine-".$query_recuperation_sgrain."-".mysql_error());
		$nb_sgrain = mysql_num_rows($result_recuperation_sgrain);
		if($nb_sgrain == 0){
			$tabF['sgrain'] = "<i> Aucun sachet de graines </i><br /><br />";
		} else {
         $cpt = 0;
			while($tab = mysql_fetch_assoc($result_recuperation_sgrain)){
			   $tabF['sgrain'][$cpt] = "<li>".$tab['QUANTITEGRAINESDISPONIBLES']." (<i>".$tab['REFERENCESACHETGRAINES']."</i>)</li>";
            $cpt++;
		   }
         $tabF['sgrain'][$cpt] = "<br />";
		}
		
		mysql_free_result($result_recuperation_sgrain);
      
      
      
      // récupération parcelles
      $query_recuperation_parc = "SELECT parc.NOMPARCELLE FROM parcelle parc ";
      $query_recuperation_parc .= "INNER JOIN touffe INNER JOIN taxon t ON t.CODETAXON = touffe.CODETAXON AND t.CODETAXON = ".$tabF['id']." AND touffe.CODEPARCELLE = parc.CODEPARCELLE ";

		$result_recuperation_parc = mysql_query($query_recuperation_parc, $connexion) or logError("GET PARCELLE-".$query_recuperation_parc."-".mysql_error());
		$nb_parc = mysql_num_rows($result_recuperation_parc);
		if($nb_parc == 0){
			$tabF['parc'] = "<i> Aucune parcelle </i><br /><br />";
		} else {
         $cpt = 0;
			while($tab = mysql_fetch_assoc($result_recuperation_parc)){
			   $tabF['parc'][$cpt] = "<li>".$tab['NOMPARCELLE']."</li>";
            $cpt++;
		   }
         $tabF['parc'][$cpt] = "<br />";
		}
		
		mysql_free_result($result_recuperation_parc);
      
      
      
      
?>
		<h3>Détail d'une plante</h3>
      
      <div class="navigation">
         <div id="oglt-ong1" class="onglet<?php if($oglt == 1) echo "-selected"; ?>"><a href="popup.php?p=gestion/plante_affiche_popup&amp;taxId=<?php echo $_GET['taxId']; ?>&amp;oglt=1" onclick="selectOnglet(1, 'oglt'); return false;">La plante</a></div>
			<div id="oglt-ong2" class="onglet<?php if($oglt == 2) echo "-selected"; ?>"><a href="popup.php?p=gestion/plante_affiche_popup&amp;taxId=<?php echo $_GET['taxId']; ?>&amp;oglt=2" onclick="selectOnglet(2, 'oglt'); return false;">Autres infos</a></div>
      
         <div id="oglt-cont1" class="contenu"  <?php if($oglt != 1) echo "style='display: none'"; ?>>
      
            <div class="planteAffiche"> 

               <div class="planteTitle">
                  <span class="planteLabel"><b>Auteur :</b></span>
         			<span class="planteContenu">
         					<ul>
         						<?php
         							echo "<li>".$tabF['auteur']."</li>";
         							echo "<br>";
         						?>
         					</ul>
         			</span>
               </div> 
               <div class="planteTitle"> 
                  <span class="planteLabel"><b>Famille :</b></span>
         			<span class="planteContenu">
         					<ul>
         						<?php
      							echo "<li>".$tabF['famille']." ".$tabF['sous_famille']."</li>";
      							echo "<br>";
      						?>
         					</ul>
         			</span>
               </div>
      			<div class="planteTitle">
                  <span class="planteLabel"><b>genre :</b></span>
         			<span class="planteContenu">
         					<ul>
         						<?php
      							echo "<li>".$tabF['genre']." ".$tabF['sous_genre']."</li>";
      							echo "<br>";
      						?>
         					</ul>
         			</span>
               </div>
      			<div class="planteTitle">
                  <span class="planteLabel"><b>Espèce :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
      							echo "<li>".$tabF['espece']." ".$tabF['sous_espece']."</li>";
      							echo "<br>";
      						?>
         					</ul>
         			</span>
               </div>
      			<div class="planteTitle">
                  <span class="planteLabel"><b>Variété :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if($tabF['variete'] == ""){
      								echo "<i> Aucune variété </i>";
                              echo "<br />";
      							} else {
                              echo "<li>".$tabF['variete']."</li>";
                           }
                           echo "<br />";
      						?>
         					</ul>
         			</span>
               </div>
            </div>
         </div>
         <div id="oglt-cont2" class="contenu" <?php if($oglt != 2) echo "style='display: none'"; ?>;>
         
            <div class="planteAffiche">
               <div class="planteTitle">
                  <span class="planteLabel"><b>Nom Vernaculaire :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_nver > 0) {
                              foreach ($tabF['nver'] as $nomVer) {
                                 echo $nomVer;
            						}
                           } else {
                              echo $tabF['nver'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
			      <div class="planteTitle">
                  <span class="planteLabel"><b>aire géographique :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_air > 0) {
                              foreach ($tabF['air'] as $nomAir) {
                                 echo $nomAir;
            						}
                           } else {
                              echo $tabF['air'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
			      <div class="planteTitle">
                  <span class="planteLabel"><b>propriétés :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_prop > 0) {
                              foreach ($tabF['prop'] as $nomProp) {
                                 echo $nomProp;
            						}
                           } else {
                              echo $tabF['prop'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
			      <div class="planteTitle">
                  <span class="planteLabel"><b>Type Biologique :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_tybi > 0) {
                              foreach ($tabF['tybi'] as $nomTybi) {
                                 echo $nomTybi;
            						}
                           } else {
                              echo $tabF['tybi'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
			      <div class="planteTitle">
                  <span class="planteLabel"><b>milieu Biologique :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_mibi > 0) {
                              foreach ($tabF['mibi'] as $nomMibi) {
                                 echo $nomMibi;
            						}
                           } else {
                              echo $tabF['mibi'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
			      <div class="planteTitle">
                  <span class="planteLabel"><b>Etat Phénologique :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_ephe > 0) {
                              foreach ($tabF['ephe'] as $nomEphe) {
                                 echo $nomEphe;
            						}
                           } else {
                              echo $tabF['ephe'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
			      <div class="planteTitle">
                  <span class="planteLabel"><b>Sachets de graines disponibles :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_sgrain > 0) {
                              foreach ($tabF['sgrain'] as $nomSg) {
                                 echo $nomSg;
            						}
                           } else {
                              echo $tabF['sgrain'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
               <div class="planteTitle">
                  <span class="planteLabel"><b>Parcelle(s) :</b></span>
         			<span class="planteContenu">
         					<ul>
         					<?php
                           if ($nb_parc > 0) {
                              foreach ($tabF['parc'] as $nomParc) {
                                 echo $nomParc;
            						}
                           } else {
                              echo $tabF['parc'];
                           }
      						?>
         					</ul>
         			</span>
               </div>
            </div>
         </div>
      </div>
	
	
<?php	
	}else{
		if(isset($_SESSION)){
			include("pages/401.htm");
		}
	}
	
?>